@extends('wap.layout')
@section('search', 'onkeydown=search();')
@section('content')
	<!--搜索框-->
	<div class="weui-search-bar" id="searchBar">
	  <form class="weui-search-bar__form" action="/user_file/folders" onkeydown="if(event.keyCode==13){return false;}">
	    <div class="weui-search-bar__box">
	      <i class="weui-icon-search"></i>
	      <input type="search" class="weui-search-bar__input" name="search_name" id="searchInput" placeholder="搜索" required="">
			<input type="hidden" name="user_file_id" id="user_file_id" />
			<input type="hidden" name="is_public" id="is_public" />
	      <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
	    </div>
	    <label class="weui-search-bar__label" id="searchText">
	      <i class="weui-icon-search"></i>
	      <span>搜索</span>
	    </label>
	  </form>
	  <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
	</div>
	<!--搜索框end-->
	<!--返回-->
	{{--<div class="gobackBar">
		<a href="/index">返回上一级</a>
	</div>--}}
	<!--返回end-->
	<!--文件列表-->
	<div class="fileList">
		<div class="weui-panel weui-panel_access">
		    <!-- body 部分 -->
		    <ul class="weui-panel__bd">

		    </ul>
		</div>
	</div>
	<!--文件列表end-->
	<div class="pldIcon"><i></i></div>
	<div class="pInfoBar">暂无文件</div>
	<!--如有文件，则显示-->
	{{--<div class="pInfoBar">298389个文件夹，49857643个文件</div>--}}
	<!--如有文件，则显示end-->
	<div class="placeHolderBar"></div>
	<!--按钮区域-->
	<div class="uploadBtnList btn btn2">
		<a href="javascript:;" id='sbtn' class="weui-btn weui-btn_primary sbtn">确定</a>
	</div>
	<!--按钮区域end-->
<style>
.weui-dialog__bd {font-size:18px}
</style>
@stop

@section('ownJs')
<script src="/js/sparkmd5.min.js"></script>
<script src="/js/upload.js"></script>
<script>
	var user_file_id = getParameterByName('user_file_id');
	var is_public = parseInt(getParameterByName('is_public'));
	var folder_id,search_name='';
$(function() {
	$('#user_file_id').val(user_file_id);
	$('#is_public').val(is_public);
	getFile();
//	getParentId();
	function getParentId() {
		$.ajax({
			type: 'get',
			url: ' /user_file/parent/' + folder_id,
			data: {is_public: is_public},
			dataType: 'json',
			success: function (result) {
				if (result.code == 0) {
					if (result.data.parent_id > 0) {
						$('.gobackBar a').attr('href', '/list?folder_id=' + result.data.parent_id + '&is_public=' + is_public);
					}
				} else if (result.code == -1) {
					location.href = '/error';
				}
			}
		});
	}
	//文件夹选择
	function toggleBtn(){
		$("li.listItem").each(function(){
			if($("li.listItem").children("label.checked").length>0){
				$(".sbtn").addClass("df")
			}else{
				$(".sbtn").removeClass("df")
			}
		})
	}
	$(document).on("click", ".labelBd", function(){
		folder_id = $(this).data('id');
		$(this).parent("label").toggleClass("checked");
		$(this).parents("li.listItem").siblings().find("label").removeClass("checked")
		toggleBtn();
	});
	$(document).on("click", "#sbtn", function() {
		var d='';
		$.modal({
			title: "移动到此文件夹下",
			text: d,
			buttons: [
				{ text: "取消", className: "default"},
				{ text: "确定", onClick: function(){ moveFile(); } },
			]
		});
	});
});
	function search(){
		if (event.keyCode==13){  //回车键的键值为13
			search_name = $('#searchInput').val();
			getFile();
		}
	}
	function getFile(){
		$.ajax({
			type:'get',
			url:' /user_file/folders',
			data:{name:search_name,is_public:is_public,user_file_id:user_file_id},
			dataType:'json',
			success:function(result){console.log(result);
				if(result.code == 0){
					var folders = result.data.folders;
					if(folders.length > 0){
						$('.pldIcon').hide();
						$('.pInfoBar').hide();
						var html = '';
						$.each(folders, function (k, v) {
							html += '<li  class="listItem">'
									+'<label class="checkLabel" for="check'+ v.id+'">'
									+'<div class="labelBd" data-id="'+ v.id+'">'
									+'<input type="checkbox" name="checkbox1" class="checkItem" id="check'+ v.id+'">'
									+'<i class="checkIcon"></i>'
									+'</div>'
									+'</label>'
									+ '<a href="javascript:void(0);" class="weui-media-box weui-media-box_appmsg">'
									+ '<div class="weui-media-box__hd">'
									+ '<i class="fileIcon floder"></i>'
									+ '</div>'
									+ '<div class="weui-media-box__bd">'
									+ '<h4 class="weui-media-box__title" id="iName'+ v.id+'">' + (v.parent_id == 0 ? "默认网盘" : v.name ) + '</h4>'
									+ '<p class="weui-media-box__desc">' + v.updated_at + '</p>'
									+ '</div>'
									+ '</a>'
									+ '</li>';
							});
						$('.fileList ul').html(html);
					}else{
						$('.fileList ul').html('');
						$('.pldIcon').show();
						$('.pInfoBar').show();
					}
				}else if(result.code == -1){
					location.href = '/error';
				}
			},
			complete:function () {

			}

		});
	}
	function moveFile(){
		$.ajax({
			type:'get',
			url:' /user_file/move/'+user_file_id,
			data:{folder_id:folder_id},
			dataType:'json',
			success:function(result){console.log(result);
				if(result.code == 0){
					location.href = '/list?folder_id='+folder_id+'&is_public='+is_public;
				}else if(result.code == -1){
					location.href = '/error';
				}
			},
			complete:function () {

			}

		});
	}
	</script>
@stop
